<template>
  <el-scrollbar class="side-bar-container student">
    <template v-for="route in routes">
      <div v-if="route['hidden'] === '1'" :key="route.id" class="menu-item-content">
        <div v-if="route['children'] && route['children'].length > 1" class="flex-row menu-item">
<!--          <i v-if="route.meta && route.meta.icon && route.meta.icon.includes('el-icon')" :class="[route.meta.icon, 'sub-el-icon']" />-->
<!--          <svg-icon v-else-if="route.meta && route.meta.icon" :icon-class="route.meta.icon ? route.meta.icon : ''" />-->
          <span>{{ route.meta.title }}</span>
        </div>
        <template v-for="subItem in route['children']">
          <div v-if="subItem['hidden'] === '1'" :key="subItem.id" :class="['flex-row', 'submenu-item-content', activeMenu === subItem['path'] ? 'active' : '']" @click="handleRouteClick(subItem)">
            <i
              v-if="subItem.meta && subItem.meta.icon && subItem.meta.icon.includes('el-icon')"
              :class="[subItem.meta.icon, 'sub-el-icon']"
            />
            <svg-icon
              v-else-if="subItem.meta && subItem.meta.icon"
              :icon-class="subItem.meta && subItem.meta.icon ? subItem.meta.icon : ''"
              style="margin-right: 5px; width: 24px"
            />
            <span :title="subItem.meta && subItem.meta.title">{{ subItem.meta && subItem.meta.title }}</span>
          </div>
        </template>
      </div>
    </template>
  </el-scrollbar>
</template>
<script>
import variables from '@/styles/variables.scss'
import { mapGetters } from 'vuex'
import { defaultOopeneds, uniqueOpened } from '@/config'
import VabSideBarItem from '@/layouts/components/VabSideBar/components/VabSideBarItem'
export default {
  name: 'VabSideBar',
  components: { VabSideBarItem },
  data() {
    return {
      title: this.$baseTitle,
      uniqueOpened
    }
  },
  computed: {
    ...mapGetters({
      logo: 'settings/logo',
      collapse: 'settings/collapse',
      routes: 'routes/routes'
    }),
    defaultOpens() {
      /* if (this.collapse) {
      }*/
      return defaultOopeneds
    },
    activeMenu() {
      const route = this.$route
      const { meta, path } = route
      if (meta['activeMenu']) {
        return meta['activeMenu']
      }
      return path
    },
    variables() {
      return variables
    }
  },
  // mounted() {
  //   console.log(this.routes, 87898)
  // },
  methods: {
    handleRouteClick(route) {
      this.$router.push({
        path: route.path
      })
    }
  }
}
</script>
<style lang="scss" scoped>
@mixin active {
  &:hover {
    color: $base-color-white;
    background-color: $base-menu-background-active !important;
  }

  &.is-active {
    color: $base-color-white;
    background-color: $base-menu-background-active !important;
  }
}

.side-bar-container {
  position: fixed;
  top: $base-nav-bar-height;
  bottom: 0;
  left: 0;
  z-index: $base-z-index;
  width: $base-left-menu-width;
  height: 100vh;
  overflow: hidden;
  background: none;
  transition: $base-transition;
  padding: 10px 20px;
  box-sizing: border-box;
  .menu-item-content {
    color: #FFFFFF;
    .menu-item {
      height: 44px;
      line-height: 44px;
      align-items: center;
      padding: 0 10px;
      color: #5C6872;
    }
    .submenu-item-content {
      height: 44px;
      line-height: 44px;
      align-items: center;
      border-radius: 8px;
      padding: 0 15px;
      box-sizing: border-box;
      cursor: pointer;
      margin-bottom: 8px;
      &:hover {
        background: linear-gradient( 90deg, #3766FF 0%, #04FFE0 100%);
      }
      &.active {
        background: linear-gradient( 90deg, #3766FF 0%, #04FFE0 100%);
      }
    }
    i, .svg-icon {
      width: 20px;
      height: 20px;
      line-height: 20px;
      font-size: 19px;
      text-align: center;
      color: #FFFFFF;
      margin-right: 8px;
    }
  }
  &.is-collapse {
    width: $base-left-menu-width-min;
    border-right: 0;

    ::v-deep {
      .el-menu {
        transition: $base-transition;
      }

      .el-menu--collapse {
        border-right: 0;

        .el-submenu__icon-arrow {
          right: 10px;
          margin-top: -3px;
        }

        .el-menu-item,
        .el-submenu {
          text-align: center;

        }
        .el-menu-item,
        .el-submenu__title {
          padding-left: 0 !important;
          padding-right: 0 !important;
        }
      }
    }
  }

  ::v-deep {
    .el-scrollbar__wrap {
      overflow-x: hidden;
    }

    .el-menu {
      border: 0;

      .vab-fas-icon {
        padding-right: 3px;
        font-size: $base-font-size-default;
        display: inline-block;
        width: 14px;
      }

      .vab-remix-icon {
        padding-right: 3px;
        font-size: $base-font-size-default + 2;
      }
    }

    .el-menu-item,
    .el-submenu__title {
      height: $base-menu-item-height;
      line-height: $base-menu-item-height;
      vertical-align: middle;
    }

    .el-menu-item {
      @include active;
    }
  }
}
</style>
